package com.jnsw.testkotlin.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jnsw.testkotlin.R;
import com.jnsw.testkotlin.bean.User;

import java.util.List;

/**
 * Created by Administrator on 2017/6/29 0029.
 */

public class MyRecyclerAdapter extends BaseQuickAdapter<User, BaseViewHolder> {

    public MyRecyclerAdapter(@Nullable List data) {//设置传参
        super(R.layout.recyitem, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, User item) {//参数处理 viewholder 控件赋值
        helper.setText(R.id.name, item.getName())
                .setText(R.id.age, String.valueOf(item.getAge()));
        helper.getView(R.id.name).setOnClickListener(new View.OnClickListener() { //点击事件 写在adapter中
            @Override
            public void onClick(View v) {
                v = (TextView)v;
                Toast.makeText(mContext,"Name Is "+((TextView) v).getText().toString(),Toast.LENGTH_SHORT).show();
            }
        });

        helper.getView(R.id.item_ll).setOnClickListener(new View.OnClickListener() { //点击事件 写在adapter中
            @Override
            public void onClick(View v) {
                int i = helper.getAdapterPosition();// 获取index
                Toast.makeText(mContext,"item 点击事件  -- "+i,Toast.LENGTH_SHORT).show();
            }
        });
    }
}
